/**
 * 树状菜单，显示在主界面的左边
 */
Ext.define('app.main.menu.MainMenuTree', {
    extend: 'Ext.tree.Panel',
    alias: 'widget.mainmenutree',
    title: localize('SystemMenu'),
    rootVisible: false,
    lines: false,
    // 导航节点点击事件  
    listeners: {
        itemclick: 'onMenuOpen'
    },
    initComponent: function () {

        console.log(abp.nav.menus.Mpa.items);
        this.store = new Ext.data.TreeStore({
            root: {
                expanded: true,
                children: []
            }
        });
        var root = this.store.getRootNode();

        Ext.Ajax.request({
            url: '/Prm/Home/GetMainMenu',
            scope: this,
            success: function (response) {
                var menus = Ext.decode(response.responseText);
                //debugger;
                console.log(menus);
                for (var i in menus.result.items) {
                    console.log(menugroup);
                    var menugroup = menus.result.items[i];

                    var menuitem = root.appendChild({
                        text: menugroup.displayName,
                        expanded: true
                        //icon: menugroup.icon,
                        // glyph: menugroup.glyph
                    });

                    for (var j in menugroup.items) {
                        var menumodule = menugroup.items[j];
                        var childnode = {
                            moduleName: menumodule.url,
                            moduleId: new Date().getTime(),
                            text: menumodule.displayName,
                            //  icon: menumodule.icon,
                            //   glyph: menumodule.glyph,
                            leaf: true
                        };
                        menuitem.appendChild(childnode);

                        var url = menumodule.url.split('.').join('-')
                        Ext.util.Cookies.set(url, menumodule.displayName, new Date(new Date().getTime() + (1000 * 60 * 60 * 24 * 30)))
                    }
                }
            }
        });

        this.callParent(arguments);
    }
})